const state = {
	articles: [],
	articleTotal: 0,
	displayArticle: {}

}
const mutations = {
	SET_ARTICLES(state, data) {
		state.articles = data.articleList;
		state.articleTotal = data.total;
	},
	SET_DISPLAYARTICLE(state, article) {
		state.displayArticle = article;
	}
}

const actions = {
	async getArticles({commit}, data) {
		let response = await uni.$u.http.get('/article/info', {
			params: {
				...data
			}
		});
		let {
			code
		} = response.data
		if (code === 200) {
			commit('SET_ARTICLES', response.data.data);
		}
		return code;
	},
	async addComment({commit},data){
		let result = await uni.$u.http.post('/comment/add',{...data,creationTime:Date.now()});
		let {code} = result.data
		return code;
	}
}

export default {
	namespaced: true,
	state,
	mutations,
	actions
}
